#ifndef CVECTORBASE_H_
#define CVECTORBASE_H_

#include "cmath.h"
#include "../exception/cindexoutofboundsexception.h"

/**
 * CVectorBase - abstract parent class for vectors
 * @author Michal Rost
 * @date 23.07.2007
 */
template <typename T> class CVectorBase : public CObject {
public:
  CVectorBase<T>& operator +=(const CVectorBase<T> &v);
  CVectorBase<T>& operator -=(const CVectorBase<T> &v);
  CVectorBase<T>& operator *=(T num);
  CVectorBase<T>& operator /=(T num);
  bool operator ==(const CVectorBase<T> &v) const;
  bool operator !=(const CVectorBase<T> &v) const;
  bool operator >(const CVectorBase<T> &v) const;
  bool operator <(const CVectorBase<T> &v) const;
  bool operator >=(const CVectorBase<T> &v) const;
  bool operator <=(const CVectorBase<T> &v) const;
  void clearToZero();
  void set(TIndex index, T value);
  void swap(TIndex index1, TIndex index2);
  void normalize();
  T getNorm() const;
  T get(TIndex index) const;
  string toString() const;
  T* getItemsPtr() const;
  virtual TIndex getSize() const = 0;
  static const TIndex VECTOR_SPACE_2D = 2;
  static const TIndex VECTOR_SPACE_3D = 3;
  static T dot(const CVectorBase<T> &v1, const CVectorBase<T> &v2);
  static string getClassName() {
    return "CVectorBase";
  }
protected:
  T* items;
  virtual void setSize(TIndex size) = 0;
  T getQuiet(TIndex index) const;
  void setQuiet(TIndex index, T value);
  void copyFrom(const CVectorBase &v);
  void createItems();
  void init(TIndex size);
  void free();
};

#endif
